package br.com.fafica.fast_restaurant.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;
import javax.swing.SwingConstants;

import br.com.fafica.fast_restaurant.model.dao.FabricaConecxao;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class TelaEditarFuncionario extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField textFieldLogin;
	private JTextField textFieldCpf;
	private JTextField textFieldSenha;
	private JTextField textFieldFone;
	private JTextField textFieldCidade;
	private JTextField textFieldCep;
	private JTextField textFieldEnd;
	private JTextField textFieldNome;
	private JTextField textFieldBairro;
	private JTextField textFieldEstado;

	public TelaEditarFuncionario(java.awt.Frame parent, boolean moda1,
			String Nome, String End, String Bairro, String Cidade,
			String Estado, String Cep, String Cpf, String Fone, String Login,
			String Senha) {

		super(parent, moda1);

		final TelaEditarFuncionario estaTela = this;
		setBounds(100, 100, 726, 418);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBackground(new Color(0, 102, 0));
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);

		JButton button = new JButton("SAIR");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				estaTela.dispose();
			}
		});
		button.setOpaque(false);

		JButton button_1 = new JButton("SALVAR");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				try {

					Connection conn = FabricaConecxao.GeraConexao();
					String query = "update cad_funcionario set nome = ?, end = ?, bairro = ?, cidade = ?,"
							+ "estado = ?, cep = ?, fone = ?, login = ?, senha = ? where cpf = ?";
					PreparedStatement cmd = conn.prepareStatement(query);

					cmd.setString(1, textFieldNome.getText());
					cmd.setString(2, textFieldEnd.getText());
					cmd.setString(3, textFieldBairro.getText());
					cmd.setString(4, textFieldCidade.getText());
					cmd.setString(5, textFieldEstado.getText());
					cmd.setString(6, textFieldCep.getText());
					cmd.setString(7, textFieldFone.getText());
					cmd.setString(8, textFieldLogin.getText());
					cmd.setString(9, textFieldSenha.getText());
					cmd.setString(10, textFieldCpf.getText());

					cmd.executeUpdate();
					cmd.close();

					JOptionPane.showMessageDialog(null,
							"Dados Atulizados Com Sucesso!!");
					estaTela.dispose();

				} catch (SQLException ex) {
					System.out.println("Ocorreu um erro sql" + ex.getMessage());
				}

			}

		});

		textFieldLogin = new JTextField();
		textFieldLogin.setText(Login);

		JLabel label = new JLabel();
		label.setText("SENHA:");
		label.setForeground(new Color(255, 215, 0));
		label.setFont(new Font("Tahoma", Font.BOLD, 12));
		label.setBackground(Color.GRAY);

		JLabel label_1 = new JLabel();
		label_1.setText("LOGUIN:");
		label_1.setForeground(new Color(255, 215, 0));
		label_1.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_1.setBackground(Color.GRAY);

		textFieldCpf = new JTextField();
		textFieldCpf.setEditable(false);
		textFieldCpf.setText(Cpf);

		textFieldSenha = new JTextField();
		textFieldSenha.setText(Senha);

		textFieldFone = new JTextField();
		textFieldFone.setText(Fone);

		textFieldCidade = new JTextField();
		textFieldCidade.setText(Cidade);

		textFieldCep = new JTextField();
		textFieldCep.setText(Cep);

		textFieldEnd = new JTextField();
		textFieldEnd.setText(End);

		textFieldNome = new JTextField();
		textFieldNome.setText(Nome);

		textFieldBairro = new JTextField();
		textFieldBairro.setText(Bairro);

		JLabel label_2 = new JLabel();
		label_2.setText("ESTADO:");
		label_2.setForeground(new Color(255, 215, 0));
		label_2.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_2.setBackground(Color.GRAY);

		textFieldEstado = new JTextField();
		textFieldEstado.setText(Estado);

		JLabel label_3 = new JLabel();
		label_3.setText("CPF:");
		label_3.setForeground(new Color(255, 215, 0));
		label_3.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_3.setBackground(Color.GRAY);

		JLabel label_4 = new JLabel();
		label_4.setText("BAIRRO:");
		label_4.setForeground(new Color(255, 215, 0));
		label_4.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_4.setBackground(Color.GRAY);

		JLabel label_5 = new JLabel();
		label_5.setText("ENDERE\u00C7O:");
		label_5.setForeground(new Color(255, 215, 0));
		label_5.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_5.setBackground(Color.GRAY);

		JLabel label_6 = new JLabel();
		label_6.setText("NOME:");
		label_6.setForeground(new Color(255, 215, 0));
		label_6.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_6.setBackground(Color.GRAY);

		JLabel label_7 = new JLabel();
		label_7.setText("CEP:");
		label_7.setForeground(new Color(255, 215, 0));
		label_7.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_7.setBackground(Color.GRAY);

		JLabel label_8 = new JLabel();
		label_8.setText("CIDADE:");
		label_8.setForeground(new Color(255, 215, 0));
		label_8.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_8.setBackground(Color.GRAY);

		JLabel label_9 = new JLabel();
		label_9.setText("FONE:");
		label_9.setForeground(new Color(255, 215, 0));
		label_9.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_9.setBackground(Color.GRAY);

		JLabel label_10 = new JLabel("CADASTRO FUNCIONARIO");
		label_10.setVerticalAlignment(SwingConstants.BOTTOM);
		label_10.setForeground(new Color(255, 215, 0));
		label_10.setFont(new Font("Arial Black", Font.PLAIN, 20));
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel
				.setHorizontalGroup(gl_contentPanel
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_contentPanel
										.createSequentialGroup()
										.addGap(23)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(180)
																		.addComponent(
																				label_10,
																				GroupLayout.PREFERRED_SIZE,
																				294,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addComponent(
																				label_6,
																				GroupLayout.PREFERRED_SIZE,
																				45,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(29)
																		.addComponent(
																				textFieldNome,
																				GroupLayout.PREFERRED_SIZE,
																				596,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addComponent(
																				label_5,
																				GroupLayout.PREFERRED_SIZE,
																				71,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(3)
																		.addComponent(
																				textFieldEnd,
																				GroupLayout.PREFERRED_SIZE,
																				596,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addComponent(
																				label_4,
																				GroupLayout.PREFERRED_SIZE,
																				71,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(3)
																		.addComponent(
																				textFieldBairro,
																				GroupLayout.PREFERRED_SIZE,
																				161,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(26)
																		.addComponent(
																				label_8,
																				GroupLayout.PREFERRED_SIZE,
																				52,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(18)
																		.addComponent(
																				textFieldCidade,
																				GroupLayout.PREFERRED_SIZE,
																				139,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(18)
																		.addComponent(
																				label_7,
																				GroupLayout.PREFERRED_SIZE,
																				35,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(4)
																		.addComponent(
																				textFieldCep,
																				GroupLayout.PREFERRED_SIZE,
																				143,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addComponent(
																				label_2,
																				GroupLayout.PREFERRED_SIZE,
																				59,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(15)
																		.addComponent(
																				textFieldEstado,
																				GroupLayout.PREFERRED_SIZE,
																				161,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(33)
																		.addComponent(
																				label_9,
																				GroupLayout.PREFERRED_SIZE,
																				45,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(18)
																		.addComponent(
																				textFieldFone,
																				GroupLayout.PREFERRED_SIZE,
																				139,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addComponent(
																				label_3,
																				GroupLayout.PREFERRED_SIZE,
																				35,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(39)
																		.addComponent(
																				textFieldCpf,
																				GroupLayout.PREFERRED_SIZE,
																				161,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addComponent(
																				label_1,
																				GroupLayout.PREFERRED_SIZE,
																				64,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(10)
																		.addComponent(
																				textFieldLogin,
																				GroupLayout.PREFERRED_SIZE,
																				239,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(18)
																		.addComponent(
																				label,
																				GroupLayout.PREFERRED_SIZE,
																				45,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(10)
																		.addComponent(
																				textFieldSenha,
																				GroupLayout.PREFERRED_SIZE,
																				284,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(225)
																		.addComponent(
																				button_1,
																				GroupLayout.PREFERRED_SIZE,
																				86,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(18)
																		.addComponent(
																				button,
																				GroupLayout.PREFERRED_SIZE,
																				70,
																				GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(
												GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		gl_contentPanel
				.setVerticalGroup(gl_contentPanel
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_contentPanel
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(label_10,
												GroupLayout.PREFERRED_SIZE, 29,
												GroupLayout.PREFERRED_SIZE)
										.addGap(28)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																label_6,
																GroupLayout.PREFERRED_SIZE,
																20,
																GroupLayout.PREFERRED_SIZE)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(1)
																		.addComponent(
																				textFieldNome,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)))
										.addGap(10)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																label_5,
																GroupLayout.PREFERRED_SIZE,
																20,
																GroupLayout.PREFERRED_SIZE)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(1)
																		.addComponent(
																				textFieldEnd,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)))
										.addGap(10)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																label_4,
																GroupLayout.PREFERRED_SIZE,
																20,
																GroupLayout.PREFERRED_SIZE)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(1)
																		.addComponent(
																				textFieldBairro,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE))
														.addComponent(
																label_8,
																GroupLayout.PREFERRED_SIZE,
																20,
																GroupLayout.PREFERRED_SIZE)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(2)
																		.addComponent(
																				textFieldCidade,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(1)
																		.addComponent(
																				label_7,
																				GroupLayout.PREFERRED_SIZE,
																				20,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(2)
																		.addComponent(
																				textFieldCep,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)))
										.addGap(10)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																label_2,
																GroupLayout.PREFERRED_SIZE,
																20,
																GroupLayout.PREFERRED_SIZE)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(1)
																		.addComponent(
																				textFieldEstado,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(8)
																		.addComponent(
																				label_9,
																				GroupLayout.PREFERRED_SIZE,
																				20,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(9)
																		.addComponent(
																				textFieldFone,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)))
										.addGap(3)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																label_3,
																GroupLayout.PREFERRED_SIZE,
																20,
																GroupLayout.PREFERRED_SIZE)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(1)
																		.addComponent(
																				textFieldCpf,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)))
										.addGap(11)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																label_1,
																GroupLayout.PREFERRED_SIZE,
																20,
																GroupLayout.PREFERRED_SIZE)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(1)
																		.addComponent(
																				textFieldLogin,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE))
														.addComponent(
																label,
																GroupLayout.PREFERRED_SIZE,
																20,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																textFieldSenha,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addGap(51)
										.addGroup(
												gl_contentPanel
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																button,
																GroupLayout.PREFERRED_SIZE,
																41,
																GroupLayout.PREFERRED_SIZE)
														.addGroup(
																gl_contentPanel
																		.createSequentialGroup()
																		.addGap(2)
																		.addComponent(
																				button_1,
																				GroupLayout.PREFERRED_SIZE,
																				37,
																				GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(30, Short.MAX_VALUE)));
		contentPanel.setLayout(gl_contentPanel);
	}

}
